import pandas as pd
from pyecharts import options as opts
from pyecharts import options as opts
from pyecharts.charts import PictorialBar
from pyecharts.globals import SymbolType
class Bookpictorialbar:
    def __init__(self):
        # 1：数据采集
        #书籍名称	借阅人姓名	班级	借阅日期	借阅天数
        bookrecords = pd.read_csv("data/书籍借阅记录.csv", encoding='utf-8-sig')
        bookcount = bookrecords['书籍名称'].groupby(bookrecords['书籍名称']).count()
        print(bookcount)
        # 3:数据可视化
        x_data = list(bookcount.keys())
        y_data = list(bookcount)
        c = (
            PictorialBar(init_opts=opts.InitOpts(width="100%", height="100%", bg_color="#e9e2e200"))
                .add_xaxis(x_data)
                .add_yaxis(
                "",
                y_data,
                label_opts=opts.LabelOpts(is_show=False),
                symbol_size=18,
                symbol_repeat="fixed",
                symbol_offset=[0, 0],
                is_symbol_clip=True,
                symbol=SymbolType.ROUND_RECT,
            )
                .reversal_axis()
                .set_global_opts(
                title_opts=opts.TitleOpts(title=""),
                xaxis_opts=opts.AxisOpts(is_show=False),
                yaxis_opts=opts.AxisOpts(
                    axistick_opts=opts.AxisTickOpts(is_show=False),
                    axisline_opts=opts.AxisLineOpts(
                        linestyle_opts=opts.LineStyleOpts(opacity=0)
                    ),
                ),
            )
                .render("templates/pictorialbar_base.html")
        )
Bookpictorialbar()
